//
//  ARMarker.m
//  ARView
//
//  Created by Niels W Hansen on 19/12/2009.
//  Copyright 2009 Agilite Software. All rights reserved.
//  Modified by Alasdair Allan on 07/04/2010.
//  Modifications Copyright 2010 Babilim Light Industries. All rights reserved.
//

#import "ARMarker.h"
#import "ARCoordinate.h"

#define BOX_WIDTH 150
#define BOX_HEIGHT 100

@implementation ARMarker

- (id)initForCoordinate:(ARCoordinate *)coordinate {
    
	NSLog(@"INICIALIZADO AO ABRIR");
	
	CGRect theFrame = CGRectMake(0, 0, BOX_WIDTH, BOX_HEIGHT);
	
	//NSLog( @"ARMarker:initForCoordinate: coordinate = %@", coordinate );
	self.backgroundColor = [UIColor clearColor];
	if (self = [super initWithFrame:theFrame]) {
		//View
		UIView *viewDet = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 120, 320)];//x,y,w,h
		viewDet.backgroundColor = [UIColor clearColor];
		
		//Imagem horizontal - linha verde
		UIImageView *pointBK	= [[UIImageView alloc] initWithFrame:CGRectZero];
		pointBK.image = [UIImage imageNamed:@"balao_ponto.png.png"];
		pointBK.frame = CGRectMake(0, 207, 120, 97);
		
		//Titulo
		UILabel *titleLabel	= [[UILabel alloc] initWithFrame:CGRectMake(0, 0, BOX_WIDTH, 20.0)];
		titleLabel.font = [UIFont fontWithName:@"Futura" size: 9.0];
		titleLabel.backgroundColor = [UIColor colorWithWhite:.3 alpha:.0];
		titleLabel.textColor = [UIColor blackColor];
		titleLabel.textAlignment = UITextAlignmentCenter;
		titleLabel.text = coordinate.coordinateTitle;
		[titleLabel sizeToFit];
		[titleLabel setFrame: CGRectMake(0,220,120,12)];
		
		//Localizacao atual

		//Distancia
		UILabel *distanciaLabel	= [[UILabel alloc] initWithFrame:CGRectMake(0, 0, BOX_WIDTH, 20.0)];
		distanciaLabel.font = [UIFont fontWithName:@"Futura" size: 9.0];
		distanciaLabel.backgroundColor = [UIColor colorWithWhite:.3 alpha:.0];
		distanciaLabel.textColor = [UIColor blackColor];
		distanciaLabel.textAlignment = UITextAlignmentCenter;
		
		coordinate.coordinateInclination = YES;
		NSString *string1= [NSString stringWithFormat:@"KM: %.1f", coordinate.coordinateDistance];
		int x = coordinate.coordinateAzimuth;
		NSString *string2=[string1 stringByAppendingFormat:@"%d ",x];
		
		distanciaLabel.text = string2;
		[distanciaLabel sizeToFit];
		[distanciaLabel setFrame: CGRectMake(0,235,120,12)];
		
		[self addSubview:viewDet];
		[self addSubview:pointBK];
		[self addSubview:titleLabel];
		[self addSubview:distanciaLabel];
		//****************************************************************************************************************************
	
		[titleLabel release];
		[viewDet release];
	}

    return self;
}

-(void)infoButtonPushed:(id)notification {

	UIView *viewDet = [[UIView alloc]initWithFrame:CGRectMake(180, 10, 420, 420)];//x,y,w,h
	viewDet.backgroundColor = [UIColor colorWithWhite:.3 alpha:.8 ];
	[self.window addSubview:viewDet];
	
	/*
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Button Pushed" message:@"Pushed the button." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];	
    [alert show];  
    [alert release]; */
	
}


- (void)dealloc {
    [super dealloc];
}


@end
